
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class LinkVenueUnitComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public LinkVenueUnitComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public LinkVenueUnit SelectOne(int VenueUnitId)
        {  
			PlacementManager.DAL.LinkVenueUnit_DAL o = new PlacementManager.DAL.LinkVenueUnit_DAL();
			o.VenueUnitId = VenueUnitId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.LinkVenueUnit LinkVenueUnitToReturn = new PlacementManager.LinkVenueUnit((int)row["VenueUnitId"], (int)row["VenueId"], (int)row["UnitId"], (int)row["CampusId"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return LinkVenueUnitToReturn;
			}
			else
			{
				PlacementManager.LinkVenueUnit LinkVenueUnitToReturnEmpty = new PlacementManager.LinkVenueUnit();
                return LinkVenueUnitToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenueUnit> SelectAll(string sortExpression)
        {
            List<LinkVenueUnit> listLinkVenueUnit = new List<LinkVenueUnit>();
            PlacementManager.DAL.LinkVenueUnit_DAL o = new PlacementManager.DAL.LinkVenueUnit_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkVenueUnit.Add(new LinkVenueUnit((int)row["VenueUnitId"], (int)row["VenueId"], (int)row["UnitId"], (int)row["CampusId"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listLinkVenueUnit.Sort(new LinkVenueUnitComparer(sortExpression));
            return listLinkVenueUnit;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenueUnit> SelectAllWUnitId(int UnitId, string sortExpression)
		{
			List<LinkVenueUnit> listLinkVenueUnit = new List<LinkVenueUnit>();
			PlacementManager.DAL.LinkVenueUnit_DAL o = new PlacementManager.DAL.LinkVenueUnit_DAL();
			o.UnitId = UnitId;
			DataSet ds = o.SelectAllWUnitId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkVenueUnit.Add(new LinkVenueUnit((int)row["VenueUnitId"], (int)row["VenueId"], (int)row["UnitId"], (int)row["CampusId"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkVenueUnit.Sort(new LinkVenueUnitComparer(sortExpression));
			return listLinkVenueUnit;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenueUnit> SelectAllWVenueId(int VenueId, string sortExpression)
		{
			List<LinkVenueUnit> listLinkVenueUnit = new List<LinkVenueUnit>();
			PlacementManager.DAL.LinkVenueUnit_DAL o = new PlacementManager.DAL.LinkVenueUnit_DAL();
			o.VenueId = VenueId;
			DataSet ds = o.SelectAllWVenueId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkVenueUnit.Add(new LinkVenueUnit((int)row["VenueUnitId"], (int)row["VenueId"], (int)row["UnitId"], (int)row["CampusId"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkVenueUnit.Sort(new LinkVenueUnitComparer(sortExpression));
			return listLinkVenueUnit;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(LinkVenueUnit o)
        {	
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit = new PlacementManager.DAL.LinkVenueUnit_DAL();
			oLinkVenueUnit.VenueId = o.VenueId;
			oLinkVenueUnit.UnitId = o.UnitId;
			oLinkVenueUnit.CampusId = o.CampusId;
			oLinkVenueUnit.IsActive = o.IsActive;
			oLinkVenueUnit.DateCreated = o.DateCreated;
			oLinkVenueUnit.CreatedBy = o.CreatedBy;
			oLinkVenueUnit.DateUpdated = o.DateUpdated;
			oLinkVenueUnit.UpdatedBy = o.UpdatedBy;

            return oLinkVenueUnit.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(int VenueId, int UnitId, int CampusId, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit = new PlacementManager.DAL.LinkVenueUnit_DAL();

			oLinkVenueUnit.VenueId = VenueId;
			oLinkVenueUnit.UnitId = UnitId;
			oLinkVenueUnit.CampusId = CampusId;
			oLinkVenueUnit.IsActive = IsActive;
			oLinkVenueUnit.DateCreated = DateCreated;
			oLinkVenueUnit.CreatedBy = CreatedBy;
			oLinkVenueUnit.DateUpdated = DateUpdated;
			oLinkVenueUnit.UpdatedBy = UpdatedBy;

            return oLinkVenueUnit.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(LinkVenueUnit o)
        {	
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit = new PlacementManager.DAL.LinkVenueUnit_DAL();
			oLinkVenueUnit.VenueUnitId = o.VenueUnitId;
			oLinkVenueUnit.VenueId = o.VenueId;
			oLinkVenueUnit.UnitId = o.UnitId;
			oLinkVenueUnit.CampusId = o.CampusId;
			oLinkVenueUnit.IsActive = o.IsActive;
			oLinkVenueUnit.DateCreated = o.DateCreated;
			oLinkVenueUnit.CreatedBy = o.CreatedBy;
			oLinkVenueUnit.DateUpdated = o.DateUpdated;
			oLinkVenueUnit.UpdatedBy = o.UpdatedBy;

            return oLinkVenueUnit.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int VenueUnitId, int VenueId, int UnitId, int CampusId, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit = new PlacementManager.DAL.LinkVenueUnit_DAL();

			oLinkVenueUnit.VenueUnitId = VenueUnitId;
			oLinkVenueUnit.VenueId = VenueId;
			oLinkVenueUnit.UnitId = UnitId;
			oLinkVenueUnit.CampusId = CampusId;
			oLinkVenueUnit.IsActive = IsActive;
			oLinkVenueUnit.DateCreated = DateCreated;
			oLinkVenueUnit.CreatedBy = CreatedBy;
			oLinkVenueUnit.DateUpdated = DateUpdated;
			oLinkVenueUnit.UpdatedBy = UpdatedBy;

            return oLinkVenueUnit.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(LinkVenueUnit o)
        {
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit_DAL = new PlacementManager.DAL.LinkVenueUnit_DAL();
            oLinkVenueUnit_DAL.VenueUnitId = o.VenueUnitId;
            return oLinkVenueUnit_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int VenueUnitId)
        {
            PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit_DAL = new PlacementManager.DAL.LinkVenueUnit_DAL();
            oLinkVenueUnit_DAL.VenueUnitId = VenueUnitId;
            return oLinkVenueUnit_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWUnitId(int UnitId)
		{
			PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit_DAL = new PlacementManager.DAL.LinkVenueUnit_DAL();
			oLinkVenueUnit_DAL.UnitId = UnitId;			
			return oLinkVenueUnit_DAL.DeleteAllWUnitId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWVenueId(int VenueId)
		{
			PlacementManager.DAL.LinkVenueUnit_DAL oLinkVenueUnit_DAL = new PlacementManager.DAL.LinkVenueUnit_DAL();
			oLinkVenueUnit_DAL.VenueId = VenueId;			
			return oLinkVenueUnit_DAL.DeleteAllWVenueId();
		}

	}
	
	public class LinkVenueUnitComparer : IComparer<LinkVenueUnit>
    {
        private string _sortColumn;
        private bool _reverse;

        public LinkVenueUnitComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(LinkVenueUnit a, LinkVenueUnit b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "VenueUnitId":
					retVal = String.Compare(a.VenueUnitId.ToString(), b.VenueUnitId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueId":
					retVal = String.Compare(a.VenueId.ToString(), b.VenueId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UnitId":
					retVal = String.Compare(a.UnitId.ToString(), b.UnitId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CampusId":
					retVal = String.Compare(a.CampusId.ToString(), b.CampusId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
